/* This is a generated file. Don't edit. Edit the source instead.
 */

#include <stdlib.h>
#include "cmd_table.h"
#include "spclient_cmd.h"

static int sp_cmd_search_response(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 10) return 0;
    int id = strtoll(argv[0], NULL, 0);
    char *hub_address = argv[1];
    char *nick = argv[2];
    char *filename = argv[3];
    int filetype = strtoll(argv[4], NULL, 0);
    uint64_t size = strtoull(argv[5], NULL, 0);
    int openslots = strtoll(argv[6], NULL, 0);
    int totalslots = strtoll(argv[7], NULL, 0);
    char *tth = argv[8];
    char *speed = argv[9];
    if(sp->cb_search_response)
        return sp->cb_search_response(sp, id, hub_address, nick, filename, filetype, size, openslots, totalslots, tth, speed);
    return 0;
}

static int sp_cmd_user_logout(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    if(sp->cb_user_logout)
        return sp->cb_user_logout(sp, hub_address, nick);
    return 0;
}

static int sp_cmd_user_login(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 9) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *description = argv[2];
    char *tag = argv[3];
    char *speed = argv[4];
    char *email = argv[5];
    uint64_t share_size = strtoull(argv[6], NULL, 0);
    int is_operator = strtoll(argv[7], NULL, 0);
    unsigned int extra_slots = strtoull(argv[8], NULL, 0);
    if(sp->cb_user_login)
        return sp->cb_user_login(sp, hub_address, nick, description, tag, speed, email, share_size, is_operator, extra_slots);
    return 0;
}

static int sp_cmd_user_update(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 9) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *description = argv[2];
    char *tag = argv[3];
    char *speed = argv[4];
    char *email = argv[5];
    uint64_t share_size = strtoull(argv[6], NULL, 0);
    int is_operator = strtoll(argv[7], NULL, 0);
    unsigned int extra_slots = strtoull(argv[8], NULL, 0);
    if(sp->cb_user_update)
        return sp->cb_user_update(sp, hub_address, nick, description, tag, speed, email, share_size, is_operator, extra_slots);
    return 0;
}

static int sp_cmd_public_message(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 3) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *message = argv[2];
    if(sp->cb_public_message)
        return sp->cb_public_message(sp, hub_address, nick, message);
    return 0;
}

static int sp_cmd_private_message(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 5) return 0;
    char *hub_address = argv[0];
    char *my_nick = argv[1];
    char *remote_nick = argv[2];
    char *remote_display_nick = argv[3];
    char *message = argv[4];
    if(sp->cb_private_message)
        return sp->cb_private_message(sp, hub_address, my_nick, remote_nick, remote_display_nick, message);
    return 0;
}

static int sp_cmd_filelist_finished(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 3) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *filename = argv[2];
    if(sp->cb_filelist_finished)
        return sp->cb_filelist_finished(sp, hub_address, nick, filename);
    return 0;
}

static int sp_cmd_hubname(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *hub_address = argv[0];
    char *new_name = argv[1];
    if(sp->cb_hubname)
        return sp->cb_hubname(sp, hub_address, new_name);
    return 0;
}

static int sp_cmd_status_message(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *hub_address = argv[0];
    char *message = argv[1];
    if(sp->cb_status_message)
        return sp->cb_status_message(sp, hub_address, message);
    return 0;
}

static int sp_cmd_download_starting(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 5) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *remote_filename = argv[2];
    char *local_filename = argv[3];
    uint64_t filesize = strtoull(argv[4], NULL, 0);
    if(sp->cb_download_starting)
        return sp->cb_download_starting(sp, hub_address, nick, remote_filename, local_filename, filesize);
    return 0;
}

static int sp_cmd_upload_starting(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 4) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    char *local_filename = argv[2];
    uint64_t filesize = strtoull(argv[3], NULL, 0);
    if(sp->cb_upload_starting)
        return sp->cb_upload_starting(sp, hub_address, nick, local_filename, filesize);
    return 0;
}

static int sp_cmd_download_finished(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *local_filename = argv[0];
    if(sp->cb_download_finished)
        return sp->cb_download_finished(sp, local_filename);
    return 0;
}

static int sp_cmd_directory_finished(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *target_directory = argv[0];
    if(sp->cb_directory_finished)
        return sp->cb_directory_finished(sp, target_directory);
    return 0;
}

static int sp_cmd_upload_finished(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *local_filename = argv[0];
    if(sp->cb_upload_finished)
        return sp->cb_upload_finished(sp, local_filename);
    return 0;
}

static int sp_cmd_transfer_aborted(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *local_filename = argv[0];
    if(sp->cb_transfer_aborted)
        return sp->cb_transfer_aborted(sp, local_filename);
    return 0;
}

static int sp_cmd_queue_add_target(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 4) return 0;
    char *local_filename = argv[0];
    uint64_t size = strtoull(argv[1], NULL, 0);
    char *tth = argv[2];
    unsigned int priority = strtoull(argv[3], NULL, 0);
    if(sp->cb_queue_add_target)
        return sp->cb_queue_add_target(sp, local_filename, size, tth, priority);
    return 0;
}

static int sp_cmd_queue_add_filelist(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *nick = argv[0];
    unsigned int priority = strtoull(argv[1], NULL, 0);
    if(sp->cb_queue_add_filelist)
        return sp->cb_queue_add_filelist(sp, nick, priority);
    return 0;
}

static int sp_cmd_queue_add_source(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 3) return 0;
    char *local_filename = argv[0];
    char *nick = argv[1];
    char *remote_filename = argv[2];
    if(sp->cb_queue_add_source)
        return sp->cb_queue_add_source(sp, local_filename, nick, remote_filename);
    return 0;
}

static int sp_cmd_queue_add_directory(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *target_directory = argv[0];
    char *nick = argv[1];
    if(sp->cb_queue_add_directory)
        return sp->cb_queue_add_directory(sp, target_directory, nick);
    return 0;
}

static int sp_cmd_queue_remove_target(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *local_filename = argv[0];
    if(sp->cb_queue_remove_target)
        return sp->cb_queue_remove_target(sp, local_filename);
    return 0;
}

static int sp_cmd_queue_remove_directory(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *target_directory = argv[0];
    if(sp->cb_queue_remove_directory)
        return sp->cb_queue_remove_directory(sp, target_directory);
    return 0;
}

static int sp_cmd_queue_remove_filelist(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *nick = argv[0];
    if(sp->cb_queue_remove_filelist)
        return sp->cb_queue_remove_filelist(sp, nick);
    return 0;
}

static int sp_cmd_queue_remove_source(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *local_filename = argv[0];
    char *nick = argv[1];
    if(sp->cb_queue_remove_source)
        return sp->cb_queue_remove_source(sp, local_filename, nick);
    return 0;
}

static int sp_cmd_hub_redirect(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *hub_address = argv[0];
    char *new_address = argv[1];
    if(sp->cb_hub_redirect)
        return sp->cb_hub_redirect(sp, hub_address, new_address);
    return 0;
}

static int sp_cmd_transfer_stats(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 4) return 0;
    char *local_filename = argv[0];
    uint64_t offset = strtoull(argv[1], NULL, 0);
    uint64_t filesize = strtoull(argv[2], NULL, 0);
    unsigned int bytes_per_sec = strtoull(argv[3], NULL, 0);
    if(sp->cb_transfer_stats)
        return sp->cb_transfer_stats(sp, local_filename, offset, filesize, bytes_per_sec);
    return 0;
}

static int sp_cmd_hub_add(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 5) return 0;
    char *hub_address = argv[0];
    char *hub_name = argv[1];
    char *nick = argv[2];
    char *description = argv[3];
    char *encoding = argv[4];
    if(sp->cb_hub_add)
        return sp->cb_hub_add(sp, hub_address, hub_name, nick, description, encoding);
    return 0;
}

static int sp_cmd_port(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    int port = strtoll(argv[0], NULL, 0);
    if(sp->cb_port)
        return sp->cb_port(sp, port);
    return 0;
}

static int sp_cmd_connection_closed(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *nick = argv[0];
    int direction = strtoll(argv[1], NULL, 0);
    if(sp->cb_connection_closed)
        return sp->cb_connection_closed(sp, nick, direction);
    return 0;
}

static int sp_cmd_connect_failed(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *hub_address = argv[0];
    if(sp->cb_connect_failed)
        return sp->cb_connect_failed(sp, hub_address);
    return 0;
}

static int sp_cmd_get_password(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *hub_address = argv[0];
    char *nick = argv[1];
    if(sp->cb_get_password)
        return sp->cb_get_password(sp, hub_address, nick);
    return 0;
}

static int sp_cmd_share_stats(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 7) return 0;
    char *path = argv[0];
    uint64_t size = strtoull(argv[1], NULL, 0);
    uint64_t totsize = strtoull(argv[2], NULL, 0);
    uint64_t dupsize = strtoull(argv[3], NULL, 0);
    unsigned int nfiles = strtoull(argv[4], NULL, 0);
    unsigned int ntotfiles = strtoull(argv[5], NULL, 0);
    unsigned int nduplicates = strtoull(argv[6], NULL, 0);
    if(sp->cb_share_stats)
        return sp->cb_share_stats(sp, path, size, totsize, dupsize, nfiles, ntotfiles, nduplicates);
    return 0;
}

static int sp_cmd_server_version(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *version = argv[0];
    if(sp->cb_server_version)
        return sp->cb_server_version(sp, version);
    return 0;
}

static int sp_cmd_user_command(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 5) return 0;
    char *hub_address = argv[0];
    int type = strtoll(argv[1], NULL, 0);
    int context = strtoll(argv[2], NULL, 0);
    char *description = argv[3];
    char *command = argv[4];
    if(sp->cb_user_command)
        return sp->cb_user_command(sp, hub_address, type, context, description, command);
    return 0;
}

static int sp_cmd_set_priority(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 2) return 0;
    char *target_filename = argv[0];
    unsigned int priority = strtoull(argv[1], NULL, 0);
    if(sp->cb_set_priority)
        return sp->cb_set_priority(sp, target_filename, priority);
    return 0;
}

static int sp_cmd_hub_disconnected(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *hub_address = argv[0];
    if(sp->cb_hub_disconnected)
        return sp->cb_hub_disconnected(sp, hub_address);
    return 0;
}

static int sp_cmd_stored_filelists(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    char *nicks = argv[0];
    if(sp->cb_stored_filelists)
        return sp->cb_stored_filelists(sp, nicks);
    return 0;
}

static int sp_cmd_init_completion(void *user_data, int argc, char **argv)
{
    sp_t *sp = user_data;
    if(sp == NULL) return 0;
    if(argc != 1) return 0;
    int level = strtoll(argv[0], NULL, 0);
    if(sp->cb_init_completion)
        return sp->cb_init_completion(sp, level);
    return 0;
}
static cmd_t sp_cmds[] = {
    {"filelist-finished", sp_cmd_filelist_finished, 3},
    {"download-starting", sp_cmd_download_starting, 5},
    {"user-logout", sp_cmd_user_logout, 2},
    {"upload-starting", sp_cmd_upload_starting, 4},
    {"status-message", sp_cmd_status_message, 2},
    {"stored-filelists", sp_cmd_stored_filelists, 1},
    {"user-command", sp_cmd_user_command, 5},
    {"queue-remove-target", sp_cmd_queue_remove_target, 1},
    {"port", sp_cmd_port, 1},
    {"user-update", sp_cmd_user_update, 9},
    {"queue-add-directory", sp_cmd_queue_add_directory, 2},
    {"connect-failed", sp_cmd_connect_failed, 1},
    {"download-finished", sp_cmd_download_finished, 1},
    {"queue-remove-filelist", sp_cmd_queue_remove_filelist, 1},
    {"upload-finished", sp_cmd_upload_finished, 1},
    {"init-completion", sp_cmd_init_completion, 1},
    {"set-priority", sp_cmd_set_priority, 2},
    {"queue-remove-source", sp_cmd_queue_remove_source, 2},
    {"queue-add-target", sp_cmd_queue_add_target, 4},
    {"transfer-stats", sp_cmd_transfer_stats, 4},
    {"queue-add-filelist", sp_cmd_queue_add_filelist, 2},
    {"search-response", sp_cmd_search_response, 10},
    {"public-message", sp_cmd_public_message, 3},
    {"server-version", sp_cmd_server_version, 1},
    {"directory-finished", sp_cmd_directory_finished, 1},
    {"get-password", sp_cmd_get_password, 2},
    {"queue-remove-directory", sp_cmd_queue_remove_directory, 1},
    {"queue-add-source", sp_cmd_queue_add_source, 3},
    {"hub-redirect", sp_cmd_hub_redirect, 2},
    {"transfer-aborted", sp_cmd_transfer_aborted, 1},
    {"hub-disconnected", sp_cmd_hub_disconnected, 1},
    {"share-stats", sp_cmd_share_stats, 7},
    {"connection-closed", sp_cmd_connection_closed, 2},
    {"hubname", sp_cmd_hubname, 2},
    {"private-message", sp_cmd_private_message, 5},
    {"user-login", sp_cmd_user_login, 9},
    {"hub-add", sp_cmd_hub_add, 5},
    {0, 0, -1}
};

sp_t *sp_init(void)
{
    sp_t *sp = calloc(1, sizeof(sp_t));
    return sp;
}

int sp_dispatch_command(const char *line, const char *delimiters,
        int allow_null_elements, sp_t *sp)
{
    return cmd_dispatch(line, delimiters, allow_null_elements,
        sp_cmds, sp);
}
